/**
 * (created at 2011-1-27)
 */
package qiushuo.mysqlparser.ast.statement;

import java.util.List;

import qiushuo.mysqlparser.ast.expression.Expression;

/**
 * @author <a href="mailto:QiuShuo1985@gmail.com">QIU Shuo</a>
 */
public class DMLReplaceStatement extends DMLStatement {
    public static final int LDH_UNDEF = 0;
    public static final int LDH_LOW = 1;
    public static final int LDH_DELAY = 2;
    private final int mode;
    private final String tableName;
    private final List<String> columnNameList;
    private final List<List<Expression>> valuesList;
    private final Expression select;

    /**
     * (replace ... values | replace ... set) format
     * 
     * @param columnNameList can be null
     */
    @SuppressWarnings("unchecked")
    public DMLReplaceStatement(int mode, String tableName, List<String> columnNameList,
                               List<List<Expression>> valuesList) {
        this.valuesList = checkAndConvertValuesList(valuesList);
        this.select = null;
        this.mode = mode;
        this.tableName = tableName;
        this.columnNameList = ensureListType(columnNameList);
    }

    /**
     * replace ... select format
     * 
     * @param columnNameList can be null
     */
    @SuppressWarnings("unchecked")
    public DMLReplaceStatement(int mode, String tableName, List<String> columnNameList, Expression select) {
        if (select == null) throw new IllegalArgumentException("argument 'select' is empty");
        this.select = select;
        this.valuesList = null;
        this.mode = mode;
        this.tableName = tableName;
        this.columnNameList = ensureListType(columnNameList);
    }

}
